package com.ldy.frame;

import com.sun.jna.NativeLibrary;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * Created by MacBook Pro on 2017/11/28.
 */
public class PFrame extends JFrame{
    //如何实现共享数据
    public static TextPanel TextVideo =new TextPanel("视频流");
    public static TextPanel TextImfo  =new TextPanel("信息流");
    public View view;


    public PFrame()
    {
        Toolkit tk =Toolkit.getDefaultToolkit();
        Dimension maxSize=tk.getScreenSize();
        int width = (int) (maxSize.getWidth()/4)*3;
        System.out.println(width);
        int hight =(int )(maxSize.getHeight()/4)*3;
        System.out.println(hight);
        this.setTitle("测试窗口");
        //添加按钮组件
        this.add(new ButtonPanel());

        //添加文本框组件
        this.add((new JPanel()).add(TextVideo));
        //添加图片信息组件
        this.add((new JPanel()).add(TextImfo));
        //添加图片显示组件
        this.add(new PImgPanel());

        //添加视屏模块
        /**
         * 尝试是否需要通过主窗口进行播放，即使用this.getMediaPlayer().playMedia("C:\\Users\\MacBook Pro\\Desktop\\娱乐\\1.mp4");
         *
         */
        view = new View();
        this.add(view);
        //this.add(view);


        //保留内容
        this.add((new JPanel()).add(new TextPanel("内容")));

        //设置为网格布局管理器
        this.setLayout(new GridLayout(2,3));

        //设置窗口位置
        this.setLocation(400,200);

        //设置窗口大小，其大小为3/4个屏幕
        this.setSize(width,hight);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        view.getMediaPlayer().playMedia("C:\\Users\\MacBook Pro\\Desktop\\娱乐\\1.mp4");
    }

    public static void main(String[] args) {
        NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(),"vlc");
        new PFrame();
    }
}
